package com.example.entity.base;

/**
 * @author chenel
 * @date 2018/3/15 14:46
 */
public class ResponseData<T> {
    private int code = 200;
    private String message = "";
    private T data;

    public static <E> ResponseData<E> ok(E data) {
        return new ResponseData(data);
    }

    public static ResponseData okMsg(String message) {
        ResponseData rd = new ResponseData();
        rd.message = message;
        return rd;
    }

    public static ResponseData fail() {
        return new ResponseData(null);
    }

    public static ResponseData fail(String message) {
        return new ResponseData(message, 500);
    }

    public static ResponseData fail(String message, int code) {
        return new ResponseData(message, code);
    }

    public static ResponseData failByParam(String message) {
        return new ResponseData(message, ResponseCode.PARAM_ERROR_CODE.getCode());
    }

    public ResponseData(T data) {
        super();
        this.data = data;
    }

    public ResponseData(ssa.web.common.enums.IMessagePairs<Integer,String> pairs) {
        super();
        this.message = pairs.message();
        this.code = pairs.code();
    }


    public ResponseData(String message, int code) {
        super();
        this.message = message;
        this.code = code;
    }

    public boolean isOk() {
        return this.code == ResponseCode.SUCCESS_CODE.getCode();
    }

    public ResponseData() {
        super();
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public ResponseData setData(T data) {
        this.data = data;
        return this;
    }

}
